package com.xinou.daily_report.controller;

import com.xinou.common.base.config.ApiResponse;
import com.xinou.common.base.exception.BusException;
import com.xinou.daily_report.PO.daily.*;
import com.xinou.daily_report.VO.*;
import com.xinou.daily_report.VO.daily.DailyInfoVO;
import com.xinou.daily_report.VO.daily.MiniDailyListVO;
import com.xinou.daily_report.service.SysDailyCommentService;
import com.xinou.daily_report.service.SysDailyService;
import com.xinou.daily_report.service.SysFlowerService;
import com.xinou.daily_report.service.SysIntegralService;
import com.xinou.daily_report.utils.ConstUtil;
import com.xinou.daily_report.utils.DailyShiroUtil;
import com.xinou.sso.service.SysDeptService;
import com.xinou.sso.util.ShiroUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author lcc
 * @create 2021-06-18
 * @注意 本内容仅限于dev414内部传阅，禁止外泄以及用于其他的商业目的
 */
@RestController
@RequestMapping("/mini/daily")
@Api(tags = {"前台 日报"})
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class MiniDailyController {

    final SysDailyService sysDailyService;
    final SysDailyCommentService sysDailyCommentService;
    final SysFlowerService sysFlowerService;
    final SysDeptService sysDeptService;
    final SysIntegralService sysIntegralService;

    @PostMapping("save")
    @ApiOperation("添加")
    @RequiresPermissions({"mini:daily:save"})
    public ApiResponse<Boolean> dailyAdd(@RequestBody DailyAddPO po)throws Exception{
        return sysDailyService.dailyAdd(po);
    }

    @PostMapping("list")
    @ApiOperation("获取列表")
    @RequiresPermissions({"mini:daily:list"})
    public ApiResponse<MiniDailyListVO> dailyList(@RequestBody DailyListPO po)throws Exception{
        return sysDailyService.miniDailyList(po);
    }

    @PostMapping("singleList")
    @ApiOperation("获取任务条款列表")
    @RequiresPermissions({"mini:daily:singleList"})
    public ApiResponse<DailySingleListVO> dailySingleList(@RequestBody DailySingleListPO po){
        return sysDailyService.dailySingleList(po);
    }

    @PostMapping("delete")
    @ApiOperation("删除")
    @RequiresPermissions({"mini:daily:delete"})
    public ApiResponse<Boolean> dailyDelete(@RequestBody DailyDeletePO po)throws Exception{
        return sysDailyService.dailyDelete(po);
    }

    @PostMapping("update")
    @ApiOperation("更新")
    @RequiresPermissions({"mini:daily:update"})
    public ApiResponse<String> dailyUpdate(@RequestBody DailyUpdatePO po) {
        if (po.getDailyId() == null) {
            throw new BusException("日报 更新异常");
        }
        return sysDailyService.dailyUpdate(po);
    }

    @PostMapping("commentList")
    @ApiOperation("获取点评列表")
    @RequiresPermissions({"mini:daily:commentList"})
    public ApiResponse<DailyCommentInfoVO> dailyCommentList(@RequestBody DailyCommentListPO po){
        return sysDailyCommentService.dailyCommentList(po);
    }

    @PostMapping("myCommentList")
    @ApiOperation("获取我的点评列表")
    @RequiresPermissions({"mini:daily:myCommentList"})
    public ApiResponse<MyCommentListVO> myCommentList(@RequestBody MyCommentListPO po){
        return sysDailyCommentService.myCommentList(po);
    }

    @PostMapping("info")
    @ApiOperation("日报详情")
    @RequiresPermissions({"mini:daily:info"})
    public ApiResponse<DailyInfoVO> dailyInfo(@RequestBody DailyInfoPO po){
        return sysDailyService.dailyInfo(po);
    }

    @PostMapping("today")
    @ApiOperation("获取日报默认值")
    @RequiresPermissions({"mini:daily:today"})
    public ApiResponse<DailyInfoVO> dailyToday(){
        return sysDailyService.dailyToday();
    }

    @PostMapping("plan")
    @ApiOperation("获取计划默认值")
    @RequiresPermissions({"mini:daily:plan"})
    public ApiResponse<DailyInfoVO> dailyPlan(@RequestBody DailyListPO po){
        return sysDailyService.dailyPlan(po);
    }

    @PostMapping("comment")
    @ApiOperation("添加评论")
    @RequiresPermissions({"mini:daily:comment"})
    public ApiResponse<String> commentSave(@RequestBody DailyCommentAddPO po){
        return sysDailyCommentService.dailyComment(po);
    }

    @PostMapping("reply")
    @ApiOperation("添加回复")
    @RequiresPermissions({"mini:daily:reply"})
    public ApiResponse<String> replySave(@RequestBody DailyReplyPO po){
        return sysDailyCommentService.dailyReply(po);
    }


    @PostMapping("scoreAdd")
    @ApiOperation("给日报加分")
    @RequiresPermissions({"mini:daily:scoreAdd"})
    public ApiResponse<Void> scoreAdd(@RequestBody DailyScoreAddPO po){
        return sysIntegralService.integralDailyScoreAdd(po);
    }

    @PostMapping("giveFlower")
    @ApiOperation("给日报送花")
    @RequiresPermissions({"mini:daily:giveFlower"})
    public ApiResponse<String> giveFlower(@RequestBody DailyFlowerAddPO po){
        return sysFlowerService.giveFlower(po);
    }

    @PostMapping("canGiveFlower")
    @ApiOperation("今天能否送花")
    @RequiresPermissions({"mini:daily:canGiveFlower"})
    public ApiResponse<Boolean> giveFlower(){
        return sysFlowerService.canGiveFlower();
    }


    @PostMapping("flowerList")
    @ApiOperation("送花列表")
    @RequiresPermissions({"mini:daily:flowerList"})
    public ApiResponse<DailyFlowerInfoVO> flowerList(@RequestBody DailyFlowerListPO po){
        return sysFlowerService.flowerList(po);
    }

    @PostMapping("submitPlan")
    @ApiOperation("提交计划")
    @RequiresPermissions({"mini:daily:submitPlan"})
    public ApiResponse<Void> submitPlan(@RequestBody DailyStatusUpdatePO po){
        po.setStatus(ConstUtil.DAILY_NO_COMMENT);
        return sysDailyService.dailyStatusUpdate(po);
    }

    @PostMapping("userList")
    @ApiOperation("员工状态列表")
    @RequiresPermissions({"mini:daily:userList"})
    public ApiResponse<DailyUserListVO> userList(@RequestBody DailyUserListPO po){
        return sysDailyService.dailyUserList(po);
    }
}
